import time

from selenium import webdriver
from selenium.webdriver.common.by import By

# 2打开浏览器
# 设置Chrome测试版本的位置
# 配置到实例
driver = webdriver.Chrome()
# 不要输入网址 密码和账户
URL = "http://10.2.0.88:8001/ui/";
UserCode = "001";
PWD = "Sit#1234"
OtherNo="888030000593639"
# PWD
# 3访问页面
driver.get(URL)

# 4页面操作(找元素+找元素操作)
# 4.1 输入用户名
driver.switch_to.frame("fraInterface")

driver.find_element(By.CSS_SELECTOR, "#UserCode").send_keys(UserCode)
driver.find_element(By.CSS_SELECTOR, "#PWD").send_keys(PWD)
driver.find_element(By.CSS_SELECTOR, "#StationCode").send_keys("86")
# 4.4点击登录
driver.find_element(By.CSS_SELECTOR, "#main > tbody > tr:nth-child(5) > td > input:nth-child(1)").click()

driver.switch_to.default_content()
driver.switch_to.frame("fraMenu")
time.sleep(3)
driver.find_element(By.CSS_SELECTOR, "#MenuTree_link_32").click()
driver.find_element(By.CSS_SELECTOR, "#MenuTree_link_47").click()
driver.switch_to.default_content()
driver.switch_to.frame("fraInterface")
BQCX = "#SelfGrid1r"
ContNO=""
IFContNO=""
Grid=""
driver_ContNO=""
BQ=""

print("BQ orgin :" + BQ)
driver.find_element(By.CSS_SELECTOR, "#OtherNo").send_keys(OtherNo)
#查询
driver.find_element(By.CSS_SELECTOR, "#fm > input:nth-child(3)").click()
#单击选中
driver.find_element(By.CSS_SELECTOR, "#AllGridExChange > tbody > tr > td:nth-child(1) > input").click()
#申请
driver.find_element(By.CSS_SELECTOR, "#fm > input:nth-child(7)").click()

whileflag= True
for i in range(1,10):
    print("BQ start :" + BQ)
    BQ = BQCX + i;
    print("BQ  end:" + BQ)
    #IFContNO=driver.find_element(By.CSS_SELECTOR, BQ).value_of_css_property()
    #整行
    driver.find_element(By.CSS_SELECTOR, "#SelfGridExChange15 > tbody > tr > td.muline.mulnotreadonlytRadio")
    ContNO = driver.find_element(By.CSS_SELECTOR, "#SelfGrid2r15").click()
    #复选框
    #ContNO = driver.find_element(By.CSS_SELECTOR, "#SelfGridExChange17 > tbody > tr").click()
    #获取value值
    IFContNO=driver_ContNO.get_attribute("value")
    print("OtherNo :" + OtherNo)
    print("IFContNO :" + IFContNO)

    if OtherNo==ContNO:
        #获得数据 对应列。grid
        Grid=BQ;
        break

    BQ = "";

print (driver.current_url)
user_name = driver.find_element(By.ID, "kw")
text_user_name = user_name.get_attribute("value")
print(text_user_name)
time.sleep(10)
# 5关闭浏览器
time.sleep(3)
driver.quit()
